package cn.edu.nju.oraldefense.action;

import javax.annotation.Resource;

import org.apache.struts2.json.annotations.JSON;

import cn.edu.nju.oraldefense.model.Teacher;
import cn.edu.nju.oraldefense.service.TeacherService;

import com.opensymphony.xwork2.ActionSupport;

public class TeacherRemoveAction extends ActionSupport {

	private int[] ids;
	private TeacherService teacherService;
	private boolean success;

	@JSON(serialize = false)
	public int[] getIds() {
		return ids;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	@JSON(serialize = false)
	public TeacherService getTeacherService() {
		return teacherService;
	}

	@Resource
	public void setTeacherService(TeacherService teacherService) {
		this.teacherService = teacherService;
	}

	public String execute() {
		if (ids != null && ids.length > 0)
			for (int i = 0; i < ids.length; i++) {
				Teacher t = new Teacher();
				t.setId(ids[i]);
				teacherService.removeTeacher(t);
			}
		success = true;
		return SUCCESS;
	}

}
